import java.util.HashMap;

/**
 * 享元工厂，存储被共享的元素
 */
public class ShapeFactory {
    private static final HashMap<String, Shape> shapes = new HashMap<String, Shape>();

    public static Shape getCircle(String color) {
        Shape colorShape = shapes.get(color);
        if (colorShape == null) {
            colorShape = new Circle(color);
            shapes.put(color, colorShape);
            System.out.println("Creating circle of color : " + color);
        }

        return colorShape;
    }
}
